package com.py.credit.controller;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.py.credit.common.rest.RestServiceResult;
import com.py.credit.service.HouseWorkService;

@RestController
@RequestMapping(value = "/housework")
public class HouseWorkController {

	@Autowired
	private HouseWorkService houseWorkService;
	
	
	@RequestMapping(value="/getRuleData.json")
	public RestServiceResult<Object> getRuleData(String tybm,String kId){
		RestServiceResult<Object> r = new RestServiceResult<>();
		try {
			List<String> list = Arrays.asList(tybm.replaceAll(" ", "").split(","));
			r.setData(houseWorkService.getScoreAndRank(list));	

		} catch (Exception e) {
            r.setCode(RestServiceResult.CODE_UNKNOW);
            r.setData("获取家政规则数据失败！");
		}
		return r;
	}
	
	@RequestMapping(value="/getIndexInfo.json")
	public RestServiceResult<Object> getIndexInfo(String data){
		RestServiceResult<Object> r = new RestServiceResult<>();
		try {
			r.setData(houseWorkService.getIndexInfo());
		} catch (Exception e) {
            r.setCode(RestServiceResult.CODE_UNKNOW);
            r.setData("获取指标数据失败！");
		}
		return r;
	}
	
	@RequestMapping(value = "/getScore.json")
	public RestServiceResult<String> getScore(
			@RequestParam(value = "tybm", required = true) String tybm) {
		RestServiceResult<String> result = new RestServiceResult<String>();
		try {
			String data = houseWorkService.getScore(tybm);
			result.setData(data);
		} catch (Exception e) {
        result.setMsg("一站式查询评价分数失败");
		}
		return result;
	}
	
}
